package com.ebt.m.customer.service;

import java.util.ArrayList;

import com.ebt.m.customer.constant.CustomerConstant;
import com.ebt.m.customer.item.Contact;
import com.ebt.m.customer.task.ImportOtherContactInfoTask;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class FetchCustomerService extends Service {

    public static final String TAG = FetchCustomerService.class.getSimpleName();

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if(intent != null){
	        int mode = intent.getIntExtra(CustomerConstant.SERVICE_FETCH_MODE, -1);
	        switch(mode){
	        case CustomerConstant.SERVICE_FETCH_CUSTOMER_IMPORT_OTHER:
	        	ArrayList<Contact> contactsWithCUuid = (ArrayList<Contact>)intent.getSerializableExtra(CustomerConstant.SERVICE_FETCH_CUSTOMER_IMPORT_OTHER_KEY);
	        	if(contactsWithCUuid != null && contactsWithCUuid.size() > 0){
		        	ImportOtherContactInfoTask importOtherTask = ImportOtherContactInfoTask.getInstance();
					importOtherTask.setContext(this);
					importOtherTask.setContactsWithCUuid(contactsWithCUuid);
					Thread t = new Thread(importOtherTask);
					t.start();
	        	}
	        	break;	
	        }
        }
        return super.onStartCommand(intent, flags, startId);  
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "FetchCustomerService in onDestroy");
    }
}
